package com.hongxun.modules.eys.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.eys.dao.EMaterialBuyDao;
import com.hongxun.modules.eys.entity.EMaterialBuyEntity;
import com.hongxun.modules.eys.service.EMaterialBuyService;


@Service("eMaterialBuyService")
public class EMaterialBuyServiceImpl implements EMaterialBuyService {
    @Autowired
    private EMaterialBuyDao eMaterialBuyDao;

    @Override
    public EMaterialBuyEntity queryObject(String guid) {
        return eMaterialBuyDao.queryObject(guid);
    }

    @Override
    public List<EMaterialBuyEntity> queryList(Map<String, Object> map) {
        return eMaterialBuyDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return eMaterialBuyDao.queryTotal(map);
    }

    @Override
    public void save(EMaterialBuyEntity eMaterialBuy) {
        if (eMaterialBuy.getGuid() == null || eMaterialBuy.getGuid().equals("")) {

            eMaterialBuy.setGuid(UUID.randomUUID().toString());
        }
        eMaterialBuyDao.save(eMaterialBuy);
    }

    @Override
    public void update(EMaterialBuyEntity eMaterialBuy) {
        eMaterialBuyDao.update(eMaterialBuy);
    }

    @Override
    public void delete(String guid) {
        eMaterialBuyDao.delete(guid);
    }

    @Override
    public void deleteBatch(String[] guids) {
        eMaterialBuyDao.deleteBatch(guids);
    }

    @Override
    public void insertOrReplaceOrDelete(List<EMaterialBuyEntity> entities) {
        for (EMaterialBuyEntity d : entities) {
            if (d.getMBDatastate().equals("删除")) {
                eMaterialBuyDao.delete(d.getGuid());
            } else {
                EMaterialBuyEntity eCrossCostEntity = eMaterialBuyDao.queryObject(d.getGuid());
                if (eCrossCostEntity == null) {
                    eMaterialBuyDao.save(d);
                } else {
                    eMaterialBuyDao.update(d);
                }
            }
        }
    }

}
